/**
 * Created by Administrator on 2016/9/27.
 */
(function($){
    $(function(){

        $(".put").val(getCookie("put"));
        $(".put2").val(getCookie("put2"));
        $(".put3").val(getCookie("put3"));
        $(".selp").val(getCookie("selp"));
        $(".selp2").val(getCookie("selp2"));
        $(".selp3").val(getCookie("selp3"));
        var sAttr=JSON.parse(getCookie("attr")),
            oCenter4 = $(".bbt2"),
            sUtm = "";

        if(sAttr.length==0){
            oCenter4.css({display:"none"});
        }else{
            oCenter4.css({display:"block"});
            for(var i=0; i < sAttr.length; i++) {
                var price=((getCookie("inpr"))*(sAttr[0].attrPrice)).toFixed(2);
                console.log(price);
                sUtm +='<li><div class="btz"><div class="center4-1"><input type="checkbox" checked="checked"> <img src="'+sAttr[0].attrSrc+'"></div><div class="center4-2"><a href="javascript:;" class="aes">'+sAttr[0].attrName+'</a></div><div class="center4-3">￥<span>'+sAttr[0].attrPrice+'</span></div><div class="center4-4"><input class="inpr" type="text" value="'+parseInt(getCookie("inpr"))+'" name="na" style="border:none;margin-left:50px;font-size:16px; outline: none;background:#fff" disabled="disabled"></div><div class="center4-5"><b>￥</b><span class="ss" >'+price+'</span></div><div class="center4-6"></div></div></li>'
            }
            $(".bbt2").html(sUtm);
            $(".ppw b").html(price);
            $(".fot-1 em").html(price);

        }
        var oBtac  =  $(".bttac table"),
            oBttap =  $(".btt-ap4 .bttz"),
            oBtsp1  =  $(".bt6 span i"),
            oBtsp2  =  $(".bt5 span i");

        oBtsp2.on("click",function(){

            if(oBttap.css("display")=="none"){
                oBtsp2.css({backgroundPosition:"0 -30px"})
                oBttap.css({display:"block"});
            }else{
                oBtsp2.css({backgroundPosition:"0 0px"})
                oBttap.css({display:"none"});
            }

        });

        oBtsp1.on("click",function(){

            if(oBtac.css("display")=="none"){
                oBtsp1.css({backgroundPosition:"0 -30px"})
                oBtac.css({display:"block"});
            }else{
                oBtsp1.css({backgroundPosition:"0 0px"})
                oBtac.css({display:"none"});
            }

        });

           //输入框判断,保存
           var Selap= $(".aasp"),
               Input1= $(".put"),
               Input2= $(".put2"),
               tAnk = $(".tank"),
               Xiang= $(".xiang p"),
               XiangA1= $(".xiang .a1t"),
               XiangA2= $(".xiang .a2t"),
               Input3= $(".put3");

        var opaxt1= getCookie("username"),
            kag1= getCookie("flag"),
            numbat2= getCookie("numb");
        if(numbat2==undefined){
            numbat2=0;
        }
        if(opaxt1.length!==undefined&&kag1==1){
            var sTrra= JSON.parse(getCookie("username"));
              console.log(sTrra);
            Input3.val(sTrra[numbat2].idcard);

        }


        Selap.on("click",function(){

            if(Input1.val()==""){
               tAnk.css({display:"block",left:"300px",top:"50px"}).animate({opacity:"1",filter:"alpha(opacity=100)"},500)


            }else if(Selp3.css("display")=="none"){
                Xiang.html("请选择最后一级城市")
                tAnk.css({display:"block",left:"300px",top:"50px"}).animate({opacity:"1",filter:"alpha(opacity=100)"},500)
            }else if(Input2.val()==""){
                Xiang.html("请填写详细地址")
                tAnk.css({display:"block",left:"300px",top:"50px"}).animate({opacity:"1",filter:"alpha(opacity=100)"},500)
            }else{
                setCookie("put",Input1.val(),30,"/");
                setCookie("put2",Input2.val(),30,"/");
                setCookie("put3",Input3.val(),30,"/");
                setCookie("selp",Selp.val(),30,"/");
                setCookie("selp2",Selp2.val(),30,"/");
                setCookie("selp3",Selp3.val(),30,"/");
                Xiang.html("保存信息成功！")
                tAnk.css({display:"block",left:"300px",top:"50px"}).animate({opacity:"1",filter:"alpha(opacity=100)"},500)
                Selp2.css({display:"none"});
                Selp3.css({display:"none"});
            }
        });
            //点击取消
        XiangA1.on("click",function(){
            tAnk.css({display:"none"}).animate({opacity:"0",filter:"alpha(opacity=0)"},500)})
        XiangA2.on("click",function(){
            tAnk.css({display:"none"}).animate({opacity:"0",filter:"alpha(opacity=0)"},500)});



           //1 三联级城市
           var Selp= $(".selp"),
               Selp2= $(".selp2"),
               Selp3= $(".selp3");

        Selp.on("click",function(){
            if(Selp.val()!="请选择"){
                Selp2.css({display:"block"});
            }
        })
        Selp2.on("click",function(){
            if(Selp2.val()!="请选择"){
                Selp3.css({display:"block"});
            }
        })

         //提交订单

        $(".fot-2 .atpa").on("click",function(){
            Xiang.html("提交表单成功")
            tAnk.css({display:"block",left:"300px",top:"600px"}).animate({opacity:"1",filter:"alpha(opacity=100)"},500)
        })


    })

})(jQuery)